<template>
  <div ref="chartRef" style="width: 100%; height: 100%"></div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

const chartRef = ref(null)
const chartInstance = ref(null)

const props = defineProps({
  data: {
    type: Array,
    default: () => []
  }
})

onMounted(() => {
  initChart()
})

const initChart = () => {
  chartInstance.value = echarts.init(chartRef.value)
  
  const option = {
    tooltip: {
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      data: props.data.map(item => item.date)
    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: props.data.map(item => item.total),
      type: 'line',
      smooth: true,
      areaStyle: {}
    }]
  }
  
  chartInstance.value.setOption(option)
}
</script>